Skip to content

fix empty object emitted for optional property with only null values#540

Merged
azahnen merged 2 commits into
masterfrom
fix-nested-null-removal
Jun 22, 2026
Merged

fix empty object emitted for optional property with only null values#540
azahnen merged 2 commits into
masterfrom
fix-nested-null-removal

Conversation

@cportele

Copy link
Copy Markdown
Contributor

FeatureTokenTransformerRemoveEmptyOptionals defers an optional object and opens it lazily when a sub-property has to be emitted. It kept null values of any property marked required, so a required-but-null sub-property forced its optional wrapper open — emitted as an empty object ({} in GeoJSON, an empty element in GML) instead of being omitted.

onValue/onGeometry now treat a property as required only if it and every wrapping property up to the feature are required, reusing the rule the context already exposes via isRequired(schema, parentSchemas). A required sub-property inside an optional object is therefore not effectively required: when all of the object's values are null the wrapper is dropped, while a wrapper that still carries non-null content drops only its null required siblings.

The change is at the token level, so both the GeoJSON and GML encoders benefit. Adds spec coverage for the all-null and partial cases.

FeatureTokenTransformerRemoveEmptyOptionals defers an optional object and
opens it lazily when a sub-property has to be emitted. It kept null values of
any property marked required, so a required-but-null sub-property forced its
optional wrapper open — emitted as an empty object ({} in GeoJSON, an empty
element in GML) instead of being omitted.

onValue/onGeometry now treat a property as required only if it and every
wrapping property up to the feature are required, reusing the rule the context
already exposes via isRequired(schema, parentSchemas). A required sub-property
inside an optional object is therefore not effectively required: when all of
the object's values are null the wrapper is dropped, while a wrapper that still
carries non-null content drops only its null required siblings.

The change is at the token level, so both the GeoJSON and GML encoders benefit.
Adds spec coverage for the all-null and partial cases.
@cportele cportele requested a review from azahnen as a code owner June 19, 2026 06:53
@azahnen azahnen enabled auto-merge (squash) June 22, 2026 07:16
@azahnen azahnen merged commit b7820af into master Jun 22, 2026
3 checks passed
@azahnen azahnen deleted the fix-nested-null-removal branch June 22, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants